package book;

/**
 * 创建一个图书类
 * 定义成员变量书名、作者、价格、书的类型、是否被借出
 * 成员变量访问权限为private权限
 * 构造方法初始化成员变量
 * 给每个成员变量创建get和set方法用来访问
 */
public class Book {
    private String name;//书名
    private String author;//作者
    private double price;//价格
    private String type;//书的类型
    private boolean isBorrowed;//是否被借出

    public Book(String name, String author, double price, String type) {
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;

    }
//调用get方法返回name，得到书名
    public String getName() {
        return name;
    }
//调用set方法，把私有成员变量name给到一个公有的name，这样就可以使用name
    public void setName(String name) {
        this.name = name;
    }
//同上述所讲
    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
//同上所述
    public boolean isBorrowed() {
        return isBorrowed;
    }

    public void setBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }

    /**
     * 重写一个toString方法，把图书转换成字符串格式
     * @return
     */
    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ((isBorrowed == true) ? "已经被借出 " : " 未被借出")
                /*", isBorrowed=" + isBorrowed*/ +
                '}';
    }
}
